﻿delete from TBL_ALERT_CARD_OVERDUE

Insert TBL_ALERT_CARD_OVERDUE
SELECT A.BUSINESS_DATE, A.CONTRACT_CIF, B.CUS_NAME
		,A.[CONTRACT_DATE_OPEN]
      ,A.[CONTRACT_NUMBER]
      ,A.[ACNT_CONTRACT_OID]
      ,A.[CONTRACT_STATUS]
      ,A.[PRODUCT_GROUP]
      ,A.[CONTRACT_TYPE]
      ,A.[ACCOUNT_LIMIT]
      ,A.[MIN_PAYMENT]
      ,A.[OVD_LEVEL]
      ,A.[BADDEBT_DATE]
      ,A.[OVD_DATE]
      ,A.[OVD_DAYS]
      ,A.[TOTAL_BALANCE]
	  , B.DAO, B.DAO_NAME, B.BRANCH_ID, D.BRANCH_NAME_SME, D.REGION 
	  FROM SERVER12.TRANGLT9.[DBO].[DAILY_CREDIT_CARD] A, TBL_CUSTOMER B, TBL_BRANCH D
WHERE A.CONTRACT_CIF = B.CIF AND B.BRANCH_ID= D.BRANCH_ID

update b
set b.date_data = (select max(BUSINESS_DATE) from TBL_ALERT_CARD_OVERDUE)
from TBL_DATE_BUSINESS b
where b.name_table = 'TBL_ALERT_CARD_OVERDUE'

--select * from SERVER12.TRANGLT9.[DBO].[DAILY_CREDIT_CARD]

--select * from TBL_ALERT_CARD_OVERDUE where dao_name = N'Nguyễn Trung Đức'

				  --SELECT * FROM TBL_CUSTOMER WHERE DAO IS NULL

